#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
import json
import logging
import logging.config

def unicode_convert(input):
    if isinstance(input, dict):
        return {unicode_convert(key): unicode_convert(value) for key, value in input.iteritems()}
    elif isinstance(input, list):
        return [unicode_convert(element) for element in input]
    elif isinstance(input, unicode):
        return input.encode('utf-8')
    else:
        return input


class Env(object):
    def __init__(self):
        self.conf = None
        try:
            with open("app.json") as f:
                self.conf = unicode_convert(json.load(f))
            if not os.path.exists("logs"):
                os.makedirs("logs")
            logging.config.fileConfig("logging.conf")
        except BaseException as e:
            print(e)
            os._exit(-1)

    def getConf(self):
        return self.conf


sysEnv = Env()
sysConf = sysEnv.getConf()

# sysLogger = logging.getLogger("main")
# restLogger = logging.getLogger("rest")

